home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / PGM_TOOL / PARAMS / SKEL.PAS < prev    next >
Pascal/Delphi Source File  |  1994-02-02  |  4KB  |  166 lines

  1. program Skel;
  2.  
  3. {%
  4.     This is a "skeleton" application; copy this file
  5.     and edit to add application-dependant operations.
  6.  
  7.     Five sections follow:
  8.  
  9.         global declarations
  10.         procedure ShowUsage
  11.         procedure SetOpt
  12.         procedure DoFile
  13.         main body
  14. }
  15.  
  16. {----------------------------------------------------------}
  17.  
  18. uses Dos, Params;    {% others?}
  19.  
  20. const
  21.     {% Identify program name, version, date, and/or copyright:}
  22.     {Update with each revision!}
  23.     CopyNote = 'SKEL prototype 11-3-93';
  24.  
  25. {configuration data; compatable with CONFIG program:}
  26. type
  27.     tConfig = record
  28.         Magic: string[10];
  29.         Data:  string[255]; {% max length = 255}
  30.     end;
  31.  
  32. const
  33.     Config: tConfig = (
  34.         Magic:    '!)@(#*$&%^';    {must appear nowhere else in code!}
  35.  
  36.         {% overwrite default options here: (51 char's per line) }
  37.         Data:    '///////////////////////////////////////////////////'+
  38.                 '///////////////////////////////////////////////////'+
  39.                 '///////////////////////////////////////////////////'+
  40.                 '///////////////////////////////////////////////////'+
  41.                 '///////////////////////////////////////////////////'
  42.                 {'/' padding reserves space for reconfiguration}
  43.     );
  44.  
  45. {----------------------------------------------------------}
  46.  
  47. {ShowUsage: explain command-line parameters and options:}
  48. procedure ShowUsage; far;
  49. begin
  50.     writeln(CopyNote);
  51.     writeln('Usage:');
  52.  
  53.     {% explain parameters & options here}
  54.  
  55.     writeln('Default options are: ', GetDefaults(Config.data));
  56. end; {ShowUsage}
  57.  
  58. {----------------------------------------------------------}
  59.  
  60. {SetOpt: set the option named OptChr to the value given by OptStr:}
  61. { Uses GetBool for booleans; e.g., /a+ /b /c- : a,b true, c false }
  62. { Uses GetInt for integers; e.g., /a-16 /b23 : sets a= -16, b= 23 }
  63. { String values are direct; e.g., /fSomeName : sets f= 'SomeName' }
  64. procedure SetOpt; far;
  65. begin
  66.     {Optn:= ExtendOpt;}     {% to use 2-char Optn instead of OptChr}
  67.     case OptChr of
  68.  
  69.         {% process option here}
  70.         {% use "if ParNo < 0" for initial-only options}
  71.  
  72.         '?': begin
  73.             PAppDone;
  74.             ShowUsage;
  75.             Halt;
  76.         end;
  77.  
  78.         {none of the above:}
  79.         else RptError('Undefined option', Option, 'u');
  80.     end;
  81. end; {SetOpt}
  82.  
  83. (*****    an alternative, for 2-character option names:  *****
  84. procedure SetOpt; far;
  85. var
  86.     Optn: ExtStr;
  87. begin
  88.     Optn:= ExtendOpt;    {try to extend option name to 2 chars}
  89.  
  90.     {use "if .. else if .." instead of "case of .."}
  91.     if Optn = 'ab' then begin
  92.  
  93.         {% process option here}
  94.         {% use "if ParNo < 0" for initial-only options}
  95.  
  96.     end else if Optn = '?' then begin
  97.         PAppDone;
  98.         ShowUsage;
  99.         Halt;
  100.     end else begin    {none of the above:}
  101.         RptError('Undefined option', Option, 'u');
  102.     end;
  103. end; {SetOpt}
  104. ***********************************************************)
  105.  
  106. {----------------------------------------------------------}
  107.  
  108. {DoFile: process the file (or name) FName:}
  109. {%
  110.     If Expdd = true, FName is expanded name of file found in Dir,
  111.     and global variables Path, Dir, and SRec may be used;
  112.     else, FName is just the ParStr, and not necessarily a filename.
  113.     Use "IsFile" to count FName as a file.
  114. }
  115. procedure DoFile(FName: PathStr; Expdd: boolean); far;
  116.  
  117.     procedure IsFile;
  118.     begin
  119.         if not Expdd then begin
  120.             inc(FileNo);  inc(FPars);
  121.         end;
  122.     end;
  123.  
  124. begin {DoFile}
  125.  
  126.     {% process file here according to options}
  127.  
  128. end; {DoFile}
  129.  
  130. {AppDone: prepare to exit from the application:}
  131. procedure AppDone; far;
  132. begin
  133.  
  134.     {% do anything needed for an orderly exit}
  135.     {.. but don't halt}
  136.  
  137. end; {AppDone}
  138.  
  139. {----------------------------------------------------------}
  140.  
  141. begin    {main program}
  142.     {mandatory: initialize procedure variables:}
  143.     PShowUsage:= ShowUsage;
  144.     PSetOpt:= SetOpt;
  145.     PDoFile:= DoFile;
  146.     PAppDone:= AppDone;
  147.  
  148.     {ParNo is < 0 here}
  149.     ParseOpts(Config.Data); {set default options}
  150.  
  151.     if ParamCount = 0 then begin    {% optional}
  152.         ShowUsage;
  153.         halt;
  154.     end;
  155.  
  156.  
  157.     {% MayExpand:= false;    -- if desired to override default}
  158.  
  159.     {ParNo := 1 to ParamCount used here:}
  160.     ScanPars;    {scan the command line}
  161.  
  162.     {% process here according to options}
  163.  
  164.     AppDone;
  165. end.
  166.